package com.wugh.fast.kernel.validator.validation;

import com.wugh.fast.kernel.core.enums.EnumInterface;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * 说明: 选项校验
 *
 * @author wugh
 * @date 2018-12-21 13:49
 */
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Repeatable(Option.List.class)
@Documented
@Constraint(validatedBy = OptionValidatorImpl.class)////此处指定了注解的实现类为ListNotHasNullValidatorImpl
public @interface Option {
    String message() default "无效选项";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    /**
     * 选项
     *
     * @return
     */
    String[] options() default {};

    /**
     * 选项表达式,通过SpringEL解析,执行结果返回结果必须是String[]
     *
     * @return
     */
    String optionsExpression() default "";

    /**
     * 继承EnumInterface的枚举,使用枚举中的code作为可选项
     * @return
     */
    Class<? extends EnumInterface> enumClass() default EnumInterface.class;

    @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
    @Retention(RUNTIME)
    @Documented
    @interface List {
        Option[] value();
    }
}
